#include "../../../common/redis.hpp"
#include "../../../common/redis_code.hpp"
#include "../../../common/redis_session.hpp"
#include "../../../common/redis_status.hpp"
#include <gflags/gflags.h>



DEFINE_string(ip,"127.0.0.1","这是服务器的IP地址");
DEFINE_int32(port,6379,"这是服务器的端口");
DEFINE_int32(db,0,"库的编号");
DEFINE_bool(keep_alive,true,"是否进行长连接保活");


void session_test(const std::shared_ptr<sw::redis::Redis>& client)
{
    Session ss(client);
    ss.append_session_id("会话ID1","用户1");
    ss.append_session_id("会话ID2","用户2");
    ss.append_session_id("会话ID3","用户3");
    ss.append_session_id("会话ID4","用户4");
    ss.append_session_id("会话ID5","用户5");


    ss.remove_session_id("会话ID1");
    ss.remove_session_id("会话ID2");

    auto res1 = ss.uid("会话ID1");
    if(res1) std::cout << *res1 << std::endl;
    auto res2 = ss.uid("会话ID2");
    if(res2) std::cout << *res2 << std::endl;
    auto res3 = ss.uid("会话ID3");
    if(res3) std::cout << *res3 << std::endl;
    auto res4 = ss.uid("会话ID4");
    if(res4) std::cout << *res4 << std::endl;
    auto res5 = ss.uid("会话ID5");
    if(res5) std::cout << *res5 << std::endl;
}

void status_test(const std::shared_ptr<sw::redis::Redis>& client)
{
    Status status(client);
    status.append_status_uid("用户ID1");  
    status.append_status_uid("用户ID2");  
    status.append_status_uid("用户ID3");  
    status.append_status_uid("用户ID4");  
    status.append_status_uid("用户ID5");

    status.remove_status_uid("用户ID3");

    if(status.exists("用户ID1")) std::cout << "用户1在线" << std::endl;   
    if(status.exists("用户ID2")) std::cout << "用户2在线" << std::endl;   
    if(status.exists("用户ID3")) std::cout << "用户3在线" << std::endl;   
    if(status.exists("用户ID4")) std::cout << "用户4在线" << std::endl;   
    if(status.exists("用户ID5")) std::cout << "用户5在线" << std::endl;   
}

void code_test(const std::shared_ptr<sw::redis::Redis>& client)
{
    Code codes(client);
    codes.append_Code("验证码ID1","验证码1");
    codes.append_Code("验证码ID2","验证码2");
    codes.append_Code("验证码ID3","验证码3");
    codes.append_Code("验证码ID4","验证码4");

    codes.remove_cid("验证码ID3");

    if(codes.code("验证码ID1")) std::cout << *codes.code("验证码ID1") << std::endl;
    if(codes.code("验证码ID2"))  std::cout << *codes.code("验证码ID2") << std::endl;
    if(codes.code("验证码ID3"))  std::cout << *codes.code("验证码ID3") << std::endl;
    if(codes.code("验证码ID4"))  std::cout << *codes.code("验证码ID4") << std::endl;
    if(codes.code("验证码ID5"))  std::cout << *codes.code("验证码ID5") << std::endl;
}

int main(int argc,char* argv[])
{
   google::ParseCommandLineFlags(&argc,&argv,true); 

   auto client = RedisClientFacyory::create(FLAGS_ip,FLAGS_port,FLAGS_db,FLAGS_keep_alive);

//    session_test(client);
//    status_test(client);
    code_test(client);
    return 0;
}